import { V3proLayout } from "../../../api/v3pro-api/v3pro.api.response.model";

/**
 * 基本布局
 * 带有高宽位置信息
 */
export class ImageLayout implements V3proLayout {
  constructor(layout: V3proLayout) {
    this.width = layout.width;
    this.height = layout.height;
    this.x = layout.x;
    this.y = layout.y;
    this.x2 = this.x + this.width;
    this.y2 = this.y + this.height;
  }

  width: number;
  height: number;
  x: number;
  y: number;
  x2: number;
  y2: number;
  isError = false;

  toJSONObj() {
    return {
      width: this.width,
      height: this.height,
      x: this.x,
      y: this.y,
      x2: this.x2,
      y2: this.y2,
      isError: this.isError,
    };
  }

  /**
   * 累计相对偏移
   * @param layout
   */
  accXY(layout: ImageLayout) {
    this.x += layout.x;
    this.y += layout.y;
    this.x2 = this.x + this.width;
    this.y2 = this.y + this.height;
    return this;
  }

  /**
   * 像素是否在布局内
   * @param pixel
   */
  inLayout(pixel: { x: number; y: number }) {
    return pixel.x >= this.x && pixel.x < this.x2 && pixel.y >= this.y && pixel.y < this.y2;
  }

  /**
   * 该模块是否异常
   */
  setError() {
    this.isError = true;
  }
}

/**
 * 像素
 */
export class Pixel {
  constructor(
    public x: number,
    public y: number,
  ) {}
}

/**
 * 错误面板
 */
export class ErrPanel {
  constructor(
    public scanBoardId: string,
    public panelIndex: number,
  ) {}
}
